# -*- coding: utf-8 -*-
"""
@Time ： 2024/4/19 14:44
@Auth ： 李天天
"""
import time

import requests

from Common.basepage import BasePage
from PageObjects.Main_page import MainPage
from PageObjects.Player_page import PlayerPage
from Common.connect_to_device import d_one, d_two, d_three
from PagePoints.click_point_for_sec import ClickPointForSec


def start_double_slave():
    BasePage(device="d_two").press_key("home")
    BasePage(device="d_three").press_key("home")
    BasePage(device="d_two").start_CPdemo_app()
    MainPage(device="d_two").click_start_share()
    MainPage(device="d_two").select_first_secren()
    MainPage(device="d_two").click_ok_share()
    time.sleep(1)
    #
    BasePage(device="d_three").start_CPdemo_app()
    time.sleep(1)
    MainPage(device="d_three").click_start_share()
    MainPage(device="d_three").select_sec_secren()
    MainPage(device="d_three").click_ok_share()


def back_to_main():
    PlayerPage(device="d_two").click_back_third()
    # ClickPointForSec().click_back_point()
    BasePage(device="d_two").press_key("home")
    PlayerPage(device="d_three").click_back_third()
    BasePage(device="d_three").press_key("home")


def press_double_slave():
    # BasePage(device="d_two").press_key("home")
    # BasePage(device="d_three").press_key("home")
    # time.sleep(2)
    while True:
        start_double_slave()
        time.sleep(3)
        BasePage(device="d_one").save_img_for_player("主驾屏起播截图")
        time.sleep(5)
        back_to_main()
        time.sleep(2)


def tt():
    BasePage(device="d_three").start_CPdemo_app()
    MainPage(device="d_three").click_start_share()
    MainPage(device="d_three").select_sec_secren()
    MainPage(device="d_three").click_ok_share()


if __name__ == '__main__':
    while True:
        try:
            press_double_slave()
        except:
            requests.get(url="https://api.day.app/s3KoLFVvWVWdYiiro2gKW/自动操作脚本可能出现问题")
